using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Deepcode.Flux.Core.Systems.CMS;
using Deepcode.Flux.Core.Services.Security;

public partial class Private_CMS_main_default : Deepcode.Flux.Core.UI.AdministrationModulePage
{
	#region Permission Code Override
	public override string RequiredPermissionCode { get { return "FluxCMSAccess"; } }
	#endregion
	#region Page Load Event
	/// <summary>
	/// Page Load event
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			int cid = GetAttribute("ContentID", -1);
			if (cid != -1)
			{
				// A content item to load has been specified
				// Ensure it
				// a) exists
				// b) is checked out
				// c) is checked out to the current user
				ContentManager cms = new ContentManager();
				ContentObject o = cms.AdxGetByID( cid );
				if( o == null ) return;
				if( o.WorkflowStatus != 0 ) return;
				if( o.FK_CheckedOutTo != CurrentUser.PK_ID ) return;
				// Ensure template exists
				if( o.TypeTemplate == null ) return;
				// Tell tree and content the last cms path is this item's parent
				SetUserSetting("CMSLASTPATH", o.FK_ParentID);
				Content.URL = Page.ResolveUrl( GetEditForm( o.TypeTemplate.EditForm, o.PK_ID ));
				Actions.URL="actions.aspx?ContentID=" + o.PK_ID;
			}
		}
	}
	#endregion
	#region Utility
	/// <summary>
	/// Gets the URL for the a content form
	/// </summary>
	/// <param name="form"></param>
	protected string GetEditForm(string form, int contentid )
	{
		string url = String.Format("{0}{1}&ContentID={2}",
			form,
			form.Contains("?") ? "" : "?",
			contentid);

		return url;
	}
	#endregion
}
